package com.example.demo.javatest.thread.Reenlock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by ljh on 2019/5/27.
 */
public class LockInterupt {
    public static void main(String[] args) {
        final Lock lock=new ReentrantLock();
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                System.out.println("t1--coming");
                try {
                    Thread.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        });

        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    lock.lockInterruptibly();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
                System.out.println("hahah");
            }
        },"t2");
        t1.start();
        t2.start();
        t2.interrupt();
    }
}
